//
//  SEGSharedRecommendModel.m
//  ExcellentHome
//
//  Created by 揭婧雯 on 2017/10/17.
//  Copyright © 2017年 陈区. All rights reserved.
//

#import "SEGSharedRecommendModel.h"

@implementation SEGSharedRecommendModel
- (instancetype)initWithDictionary:(NSDictionary*)dictionary
{
    self = [super init];
    if (self) {
        _operationType = @"";
        _content = @"";
        _objId = @"";
        _browseCount = @"";
        _objType = @"";
        _picture = @"";
        _tag = @"";
        _title = @"";
        [self setValuesForKeysWithDictionary:dictionary];
    }
    return self;
}
+ (instancetype)initWithDictionary:(NSDictionary*)dictionary
{
    return [[self alloc] initWithDictionary:dictionary];
}
- (void)setValue:(id)value forUndefinedKey:(NSString*)key
{}
- (void)setOperationType:(NSString*)operationType{
    _operationType = [[SEGUtils ValueToString:operationType]copy];
}
- (void)setContent:(NSString*)content{
    _content = [[SEGUtils ValueToString:content]copy];
}
- (void)setObjId:(NSString*)objId{
    _objId = [[SEGUtils ValueToString:objId]copy];
}
- (void)setBrowseCount:(NSString*)browseCount{
    _browseCount = [[SEGUtils ValueToString:browseCount]copy];
}
- (void)setObjType:(NSString*)objType{
    _objType = [[SEGUtils ValueToString:objType]copy];
}
- (void)setPicture:(NSString*)picture{
    _picture = [[SEGUtils ValueToString:picture]copy];
}
- (void)setTag:(NSString*)tag{
    _tag = [[SEGUtils ValueToString:tag]copy];
}
- (void)setTitle:(NSString*)title{
    _title = [[SEGUtils ValueToString:title]copy];
}

- (void)encodeWithCoder:(NSCoder *)encoder
{
    unsigned int count = 0;
    objc_property_t *propertes = class_copyPropertyList([self class], &count);
    for (int i=0; i<count; i++) {
        const char *propertyName = property_getName(propertes[i]);
        NSString *name = [NSString stringWithUTF8String:propertyName];
        id value = [self valueForKey:name];
        [encoder encodeObject:(value)?value:@"" forKey:name];
    }
}

- (id)initWithCoder:(NSCoder *)decoder
{
    if (self = [super init]) {
        unsigned int count =0;
        objc_property_t *propertes = class_copyPropertyList([self class], &count);
        for (int i = 0; i < count; i++) {
            const char *propertyName = property_getName(propertes[i]);
            NSString *name = [NSString stringWithUTF8String:propertyName];
            id value = [decoder decodeObjectForKey:name];
            [self setValue:(value)?value:@"" forKey:name];
        }
        
    }
    return self;
}

@end
